package 找树根和孩子;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    static int N = 1010;
    static boolean[] st = new boolean[N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        ArrayList<ArrayList<Integer>> arrayList = new ArrayList<>();
        for (int i = 0; i <= 1000; i++) {
            arrayList.add(new ArrayList<>());
        }
        for (int i = 0; i < m; i++) {
            int father = in.nextInt();
            int son = in.nextInt();
            st[son] = true;
            arrayList.get(father).add(son);
        }
        for (int i = 1; i <= 1000; i++) {
            if (!st[i] && arrayList.get(i).size() > 0) {
                System.out.println(i);
                break;
            }
        }
        int j = 1;
        for (int i = 2; i <= 1000; i++) {
            if (arrayList.get(i).size() > arrayList.get(j).size()) {
                j = i;
            }
        }
        System.out.println(j);
        Collections.sort(arrayList.get(j));
        for (int i = 0; i < arrayList.get(j).size(); i++) {
            System.out.print(arrayList.get(j).get(i) + " ");
        }
    }
}
